package com.karileet.nokia.meeting.profile;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Switch;

@SuppressLint("ParserError")
public class MeetingProfile {
	private Context ctx;

	public MeetingProfile(Context ctx) {
		this.ctx = ctx;
	}

	public boolean enable(ProfileState state) {
		ProfileNotifications notification = new ProfileNotifications(ctx);
		UserConf uc = new UserConf(ctx);
		uc.save();
		if (state.isVibrateEnabled()) {
			uc.set(AudioManager.RINGER_MODE_VIBRATE);
		} else {
			uc.set(AudioManager.RINGER_MODE_SILENT);
		}
		notification.initiateNotification();
		storeToSharedPrefs(true);
		return true;
	}

	public boolean disable() {
		ProfileNotifications notification = new ProfileNotifications(ctx);
		UserConf uc = new UserConf(ctx);
		int mode = uc.read();
		uc.set(mode);
		notification.cancelNotification();
		storeToSharedPrefs(false);
		return true;
	}

	@SuppressLint("ParserError")
	private void storeToSharedPrefs(boolean state) {
		SharedPreferences p = ctx.getSharedPreferences(MainActivity.PREFS_NAME,
				0);
		p.edit().putBoolean("profile", state).commit();
	}
}
